<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <base href="/oa1/" />
    <title>发布信息</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="static/bootstrapvalidator/css/bootstrapValidator.css" rel="stylesheet">
    <link href="static/summernote/summernote.css" rel="stylesheet">
    <script src="static/jquery/jquery-1.10.2.min.js"></script>
    <script src="static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="static/bootstrapvalidator/js/bootstrapValidator.js"></script>
    <script src="static/summernote/summernote.js"></script>
    <script src="static/summernote/lang/summernote-zh-CN.js"></script>
</head>
<body>
<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">发布新闻通知公告</h4>
    </div>

    <form action="xx/information/addInformation" enctype="multipart/form-data" id="myform" method="post" class="form-horizontal">
        <div class="panel-body">
            <div class="form-group col-md-12">
                <div class="col-md-6">
                    <label for="title" class="col-md-4 control-label">信息标题</label>
                    <div class="col-md-8">
                        <input type="text" id="title" name="title" class="form-control" placeholder="请输入信息标题">
                    </div>
                </div>
                <div class="col-md-6">
                    <label for="typeid" class="col-md-4 control-label">消息类别</label>
                    <div class="col-md-8">
                        <select id="typeid" name="typeid" class="form-control">
                            <option value="">--请选择--</option>
                            <option value="1">公司新闻</option>
                            <option value="2">通知公告</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group col-md-12">
                <div class="col-md-11 col-md-offset-1">
                    <textarea id="summernote" class="summernote"></textarea>
                    <input type="hidden" id="content" name="content"/>
                </div>
            </div>

            <div class="form-group col-md-12">
                <div class="col-md-6">
                    <label for="accpath" class="col-md-4 control-label">信息附件</label>
                    <div class="col-md-8">
                        <input type="file" id="accpath" name="accpath">
                    </div>
                </div>
                <div class="col-md-6">
                    <label for="closeDate" class="col-md-4 control-label">停止时间</label>
                    <div class="col-md-8">
                        <input type="date" id="closeDate" name="closeDate" class="form-control" min="${java.time.LocalDate.now()}">
                    </div>
                </div>
            </div>

            <div class="form-group col-md-12">
                <div class="col-md-10 col-md-offset-2">
                    <button type="submit"  class="btn btn-success">确认发送</button>
<%--                    <button type="button" id="editInformationBtn" class="btn btn-success">确认发送</button>--%>
                    <button type="reset" id="resetbtn" class="btn btn-default">取消</button>
                </div>
            </div>
        </div>
    </form>
</div>

<!-- 提示模态框 -->
<div class="modal fade" id="alertMsgModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-xs">
        <div class="modal-content">
            <div class="modal-body" id="alertmsg"></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        // 初始化富文本编辑器
        $('#summernote').summernote({
            lang: 'zh-CN',
            height: 200,
            placeholder: '请输入内容...',
            callbacks: {
                onChange: function() {
                    $("#content").val($(this).summernote('code')); // 同步内容到隐藏域
                }
            }
        });

        // 表单验证
        $("#myform").bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    validators: {
                        notEmpty: {message: '标题不能为空'},
                        stringLength: {min:1, max:50, message: '标题长度1-50位'}
                    }
                },
                typeid: {
                    validators: {
                        notEmpty: {message: '请选择类别'}
                    }
                }
            }
        });

        // 提交表单
        $("#editInformationBtn").click(function(){
            if($('#myform').data("bootstrapValidator").isValid()){
                if ($('#summernote').summernote('isEmpty')) {
                    $("#alertmsg").text("请输入内容!");
                    $('#alertMsgModal').modal('show');
                    return;
                }
                $("#myform").submit();
            }
        });
    });
</script>
</body>
</html>